import {Pipe, PipeTransform} from "@angular/core";
import {environment} from '../../../environments/environment';
import {SupportLanguage} from '../models/common/support-language';

@Pipe({name: 'localize', pure: false})
export class LocalizedValuePipe implements PipeTransform {
    localizedValue: string;

    transform(value: any, enPropertyName: string, cnPropertyName: string): string {
        this.localizedValue = value;
        if (value) {
            this.localizedValue = environment.activeLanguage == SupportLanguage.zh_cn ? value[cnPropertyName ?
                cnPropertyName : enPropertyName] : value[enPropertyName ? enPropertyName : cnPropertyName];
        }

        return this.localizedValue;
    }
}
